﻿
document.oncontextmenu=function(e){return false;} 
var vList = new CtnListCtrl("vList");
var vRouteList = new CtnListCtrl("vRouteList");
vList.create("result");
vRouteList.create("LineRoute");
vList.bpage = 1;
vList.pagesize = 10;
vList.onGoPage = gotoPage;
vList.onRowClick = onRowClick;
vRouteList.onRowRClick = onMyRightMenu;
var vExp = ""  
var strsql = null;
var glid = null;
var id0 = null;
var restype = null;
var rescodeid = null;
var restypeid = null;
var SxJx = null;
var major = 0;
var minor = 0;
function InitFggl()
{
    var allinput = document.getElementsByTagName("input");
    var allselect = document.getElementsByTagName("select");
    var JxFlag = $F("JxEconAlySvr");
    if(JxFlag == 1)
    {
       $("QuerSx").style.visibility = "hidden";
       $("QuerAdd").style.visibility = "hidden";
       $("EditFg").style.visibility = "hidden";
       $("Addcover").style.visibility = "hidden";
       $("DeleFg").style.visibility = "hidden";
    }
    for(var i = 0;i<allinput.length;i++)
    {
        if(allinput[i].type != "checkbox" && allinput[i].type != "button")
        {
            allinput[i].disabled = true;
            allinput[i].style.backgroundColor = "#F5F5F5"
        }
    }
    for(i = 0;i<allselect.length;i++)
    {
        allselect[i].disabled = true;
        allselect[i].style.backgroundColor = "#F5F5F5"
    }
}

function onRowClick(evt, rowno)
{
    var rowobj = vList.getRow(rowno);
    glid = rowobj.getCell("GLID");
    id0 = rowobj.getCell("ID0");
    restype = rowobj.getCell("RESTYPE");
    rescodeid = rowobj.getCell("RESCODEID");
    restypeid = rowobj.getCell("RESTYPEID");
    SxJx = rowobj.getCell("JXBM");
}
function Query()
{
    major = 95;
    minor = 541
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'view', null])
}
function QueryRoute()
{
   if(rescodeid == null)
   {
       CtnDlg.warning("请选择记录");
       return ;
   }        
   var url = "/main.ashx?_method=ShowDlRoute" + "&Devid=" + rescodeid.text + "&DevType=" + restype.text;
   var xmlDoc = CtnTrans.getText(url);
   if (!CtnError.validate(xmlDoc))
   {
        CtnError.show();
        return;
   }
   else if(xmlDoc != "false")
   {            
        vRouteList.reset();
        vRouteList.insertXml(xmlDoc, 1);
        vRouteList.show();
   }   
   
}
//根据资源ID，资源类型定位
function LocByResCover()
{
   if(rescodeid == null)
   {
       CtnDlg.warning("请选择记录");
       return ;
   }   
   //var vMajor = CtnMajorDef.TEL_MAJ_PNT;  
   top.ExecuteATool(top.m_vt.FUN_LOC,[CtnMajorDef.TEL_MAJ_PNT, restypeid.text, rescodeid.text]);  
}

//根据局向链接到选号系统
function SelectNumByJx()
{ 
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    if(SxJx == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
   var url = "/main.ashx?_method=SelectNumUrl" + "&Jx=" + SxJx.text;
   var xmlDoc = CtnTrans.getText(url);
   if (!CtnError.validate(xmlDoc))
   {
        CtnError.show();
        return;
   }
   else if(xmlDoc != "false")
   {            
       window.open(xmlDoc);
   }  
}

function onMyRightMenu(evt, rowno)
{
    mc = new CtnMenuCtrl("mc");
    mc.bOutHide  = true;      
          
    var vJuId = vRouteList.getRow(rowno).getCell("juid").text;
    var vHuId = vRouteList.getRow(rowno).getCell("huid").text;
    var vJuMajor = vRouteList.getRow(rowno).getCell("jumajor").text;
    var vJuMinor = vRouteList.getRow(rowno).getCell("juminor").text;
    var vHuMajor = vRouteList.getRow(rowno).getCell("humajor").text;
    var vHuMinor = vRouteList.getRow(rowno).getCell("huminor").text;        
    var vXxLy = vRouteList.getRow(rowno).getCell("dlid").text;
    var vTelNumLy = "";
    var vDlMajor = CtnMajorDef.TEL_MAJ_ATT;
    var vDlMinor = CtnMinorDef.TEL_ATT_DL;
    for (var i = 0; i < vRouteList.arrRow.length; i++)
    {
        if (vRouteList.getRow(i).getCell("dlbm") != null)
        {
           if(vTelNumLy == "")
           {
               vTelNumLy += vRouteList.getRow(i).getCell("dlid").text;
           }
           else
           {
               vTelNumLy += "," + vRouteList.getRow(i).getCell("dlid").text;
           }
        }
    }

    mc.addEvent("定位近局方设施", "top.EntityLocatByNo("+vJuMajor+", "+vJuMinor+", "+vJuId+")");
    mc.addEvent("定位近户方设施", "top.EntityLocatByNo("+vHuMajor+", "+vHuMinor+", "+vHuId+")");
    
    mc.addEvent("查询线序路由", "LocateByDlXx('"+vDlMajor+"','"+vDlMinor+"','"+vXxLy+"')");          
    mc.addEvent("查询号码路由", "LocateByDlXx('"+vDlMajor+"','"+vDlMinor+"','"+vTelNumLy+"')");
    
    mc.show(evt);                                       
} 
  
//根据实体号定位
function LocateByDlXx(major, minor, DlId)
{  
   var serverUrl = "_method=LocateDlLy&Dlid="+ DlId +"&major=" + escape(major) + "&minor=" + escape(minor);
   //var major = CtnMajorDef.TEL_MAJ_ATT;
   //var minor = CtnMinorDef.TEL_ATT_DL;
   var entityNo = DlId;                      
   CtnTrans.Ajax("/main.ashx","post",serverUrl, top.EntityNoLocat,{maj:major,min:minor,ent:entityNo}, {loading:true});   
}

//根据号码定位
function LocateByTelNum(TelNum)
{

    var vData = top.CtnTrans.getText("/main.ashx?", "post", "_method=LocateByNum&Num=" + escape(TelNum)); 
    if (!top.CtnError.validate(vData ))
    {
         top.CtnError.show();
         return;
     }
     else
     {
        var vXmlDoc = CtnXML.getXmlDoc();
        vXmlDoc.loadXML(vData);            
        var vMajor = vXmlDoc.selectNodes("items/Major");
        var vMinor = vXmlDoc.selectNodes("items/Minor");
        var vEntNo= vXmlDoc.selectNodes("items/EntityNo");
        
        if ($XML(vMajor[0]) != undefined || $XML(vMinor[0]) !=undefined ||$XML(vEntNo[0]) !=undefined)
        {
            LocateByDlXx($XML(vMajor[0]), $XML(vMinor[0]), $XML(vEntNo[0]));
        }
       
     }               
}
   
function QueryAddr()
{
    major = 95;
    minor = 864;
    if(glid== null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, glid.text, 'view', null])
}
function EditResCover()
{
    major = 95;
    minor = 541;
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, id0.text, 'edit', Edit])
}
function AddCover()
{
    major = 95;
    minor = 541;
    top.ExecuteATool(top.m_vt.FUN_ATT, [major, minor, 0, 'add', GetAddcover])
}
function GetAddcover(dlg)
{
    var vGrid = dlg.wnd.getXml()
    if(vGrid == false)
    {
        return;
    }
    var url = "/main.ashx?_method=AddCover&maj=95&min=541&strsql="+strsql+"&pageno="+vList.curpage+"&size="+vList.pagesize+"&vGrid"+vGrid;
    var xmlDoc = CtnTrans.getText(url, "post", escape(vGrid));
    if (!CtnError.validate(xmlDoc))
    {
        CtnError.show();
        return;
    }
    else if(xmlDoc != "false")
    {            
        vList.reset();
        vList.insertXml(xmlDoc, 1);
        vList.show();
    }   
    dlg.close();
}
function DeleteCover()
{
    if(id0 == null)
    {
        CtnDlg.warning("请选择记录");
        return ;
    }
    if (confirm("请确认该区域下的实体已经清空，确认是否删除该区域？"))
    {
        var vParam = "_method=DeleteCover&maj=95&min=541&id="+id0.text + "&strsql="+escape(strsql)+"&pageno="+vList.curpage+"&size="+vList.pagesize;
        var xmlDoc = CtnTrans.getText("/main.ashx", "post", vParam)
        if (!CtnError.validate(xmlDoc))
        {
            CtnError.show();
            return;
        }
        else if(xmlDoc != "false")
        {            
            vList.reset();
            vList.insertXml(xmlDoc, 1);
            vList.show();
        }   
    }
}
function Edit(dlg)
{
    var vGrid = dlg.wnd.getXml()
    var xmlDoc = CtnTrans.getText("/main.ashx?_method=EditCover&maj=95&min=541&id="+id0.text+ "&strsql="+escape(strsql)+"&pageno="+vList.curpage+"&size="+vList.pagesize, "post", escape(vGrid))
    if (!CtnError.validate(xmlDoc))
    {
        CtnError.show();
    }
    else if(xmlDoc == "false")
    {
        vList.reset();
    }
    else    
    {            
        vList.reset();
        vList.insertXml(xmlDoc, 1);
        vList.show();
    }   
    dlg.close()
}

function chaxun_onclick()
{
    var ischeck = 0;
    strsql = null;
    if(document.getElementById("Check_zdjp").checked)
    {
        strsql = "CYJP like '%" + document.getElementById("Text_zdjp").value + "%'";
        ischeck = 1;
    }
    if(document.getElementById("Check_cyzw").checked)
    {
        if(ischeck == 0)
        {
            strsql = "CYDZ like '%" + document.getElementById("Text_xyzw").value + "%'";
        }
        else
        {
            strsql += " and CYDZ like '%" + document.getElementById("Text_xyzw").value + "%'";
        }
        ischeck = 1;
    }
    if(document.getElementById("Check_zylx").checked)
    {
        if(ischeck == 0)
        {
            strsql = "NETRESTYPE =" + document.getElementById("Select_zylx").value + " and NETRESCODE like '%" + document.getElementById("Text_zylx").value + "%'";
        }
        else
        {
            strsql += " and NETRESTYPE =" + document.getElementById("Select_zylx").value + " and NETRESCODE like '%" + document.getElementById("Text_zylx").value + "%'";
        }
        ischeck = 1;
    }
    if(document.getElementById("Check_Jx").checked)
    {
        if(ischeck == 0)
        {
            strsql = "JXBM like '" +document.getElementById("Text_Jx").value + "%'";
        }
        else
        {
            strsql += " and JXBM like '" +document.getElementById("Text_Jx").value + "%'";
        }
        ischeck = 1;
    }
//    if(document.getElementById("Check_zdkjp").checked)
//    {
//        if(ischeck == 0)
//        {
//        
//        }
//        else
//        {
//            
//        }
//    }
//    if(document.getElementById("Check_dzzw").checked)
//    {
//        if(ischeck == 0)
//        {
//        
//        }
//        else
//        {
//            
//        }
//    }
    if(document.getElementById("Check_qyzt").checked)
    {
        if(ischeck == 0)
        {
            strsql = "STATUS = '" + document.getElementById("Select_qyzt").value + "'";
        }
        else
        {
            strsql += " and STATUS = '" + document.getElementById("Select_qyzt").value + "'";
        }
    }
    if(strsql == "" || strsql == null)
    {
        top.CtnDlg.error("查询条件为空");
        return ;
    }
    
    vList.onGoPage(1);
    
//    var vParam = "_method=Fggl&major=95&minor=541&strsql=" + strsql + "&pageno=1&size="+vList.pagesize
//    var vData = CtnTrans.getText("/main.ashx?","post",vParam);
//    if (!CtnError.validate(vData))
//    {
//        CtnError.show();
//        return;
//    }
//    else
//    {
//        vList.reset();
//        vList.insertXml(vData, 1);
//        vList.show();
//    }
}
function gotoPage(page)
{
    var vUrl = "_method=Fggl&major=95&minor=541&strsql="+escape(strsql)+"&pageno="+page+"&size="+vList.pagesize
    var vData = CtnTrans.getText("/main.ashx", "post", vUrl);
    if (!CtnError.validate(vData))
    {
        CtnError.show()
        return;
    }
    else
    {
        vList.reset();
        vList.insertXml(vData, 1);
        vList.show();
    }
}
function expand(id,value)
{
    if ($(value).style.display == "none")
    {
        $(value).style.display = "block"
        $(id).src = "../Images/tree/elbow-end-minus-nl.gif"
    }
    else
    {
        $(value).style.display = "none"
        $(id).src = "../Images/tree/elbow-plus-nl.gif"
    }
}
function Resetcheck(ID,obj) 
{
    if(ID.checked)
    {   
        if(obj == "Select_zylx")
        {
            document.getElementById(obj).disabled = false
            document.getElementById(obj).style.backgroundColor = "#FFFFFF"
            document.getElementById("Text_zylx").disabled = false
            document.getElementById("Text_zylx").style.backgroundColor = "#FFFFFF"   
            document.getElementById("button_chaxun").disabled = false         
        }
        else if(obj == "Select_dzzw")
        {
            document.getElementById(obj).disabled = false  
            document.getElementById(obj).style.backgroundColor = "#FFFFFF"
            document.getElementById("Text_dzzw").disabled = false  
            document.getElementById("Text_dzzw").style.backgroundColor = "#FFFFFF" 
            document.getElementById("button_chaxun").disabled = false         
        }
        else if(obj == "Select_dmbg")
        {
            document.getElementById(obj).disabled = false
            document.getElementById(obj).style.backgroundColor = "#FFFFFF"
            document.getElementById("Text_qsrq").disabled = false  
            document.getElementById("Text_qsrq").style.backgroundColor = "#FFFFFF" 
            document.getElementById("Text_jxrq").disabled = false  
            document.getElementById("Text_jxrq").style.backgroundColor = "#FFFFFF" 
            document.getElementById("button_chaxun").disabled = false         
        }
        else
        {
            document.getElementById(obj).disabled = false
            
            document.getElementById(obj).style.backgroundColor = "#FFFFFF"   
            document.getElementById("button_chaxun").disabled = false         
        }
    }
    else
    {
        if(obj == "Select_zylx")
        {
            document.getElementById(obj).disabled = true 
            document.getElementById(obj).style.backgroundColor = "#F5F5F5"
            document.getElementById("Text_zylx").disabled = true
            document.getElementById("Text_zylx").value = ""
            document.getElementById("Text_zylx").style.backgroundColor = "#F5F5F5"            
        }
        else if(obj == "Select_dzzw")
        {
            document.getElementById(obj).disabled = true
            document.getElementById(obj).style.backgroundColor = "#F5F5F5"
            document.getElementById("Text_dzzw").disabled = true  
            document.getElementById("Text_dzzw").value = ""
            document.getElementById("Text_dzzw").style.backgroundColor = "#F5F5F5" 
        }
        else if(obj == "Select_dmbg")
        {
            document.getElementById(obj).disabled = true
            document.getElementById(obj).style.backgroundColor = "#F5F5F5"
            document.getElementById("Text_qsrq").disabled = true
            document.getElementById("Text_qsrq").value = ""
            document.getElementById("Text_qsrq").style.backgroundColor = "#F5F5F5" 
            document.getElementById("Text_jxrq").disabled = true
            document.getElementById("Text_jxrq").value = ""
            document.getElementById("Text_jxrq").style.backgroundColor = "#F5F5F5" 
        }
        else
        {
            document.getElementById(obj).disabled = true
            document.getElementById(obj).value = ""
            document.getElementById(obj).style.backgroundColor = "#F5F5F5"
        }
    }
}